<template>
	<view class="mainpadding">
		<!-- 展示地址 -->
		<view class="ffffff mainpadding radius mainpadding" v-if="address_id" @click="dizhi">
			<view class="flexbetween">
				<view class="">
					<view class="flexleft">
						<view class="titletext hei_text bold margin_right">{{dataAll.address_info.name}}</view>
						<view class="titletext hei_text bold">{{dataAll.address_info.mobile}}</view>
					</view>
					<view class="margin_top2 xiaohui">{{dataAll.address_info.region}}{{dataAll.address_info.address}}
					</view>
				</view>
				<u-icon name="arrow-right" color="#999" size="12"></u-icon>
			</view>
		</view>
		<!-- 添加地址 -->
		<view class="biabox flexcenter ffffff radius" v-else @click="dizhi">
			<view class="textcenter dhtext">点击添加收货地址</view>
		</view>
		<view class="mainpadding_top ffffff radius flexleft" v-for="item in dataAll.goods_data" :key="item.goods_id">
			<image :src="item.image_text" class="listleftimg radius" mode=""></image>
			<view class="flexcolumnbet margin_left2" style="height: 140rpx;width: 100%;">
				<view class="hei_text bold main_size yihang">{{item.goods_name}}</view>
				<view class="xiaohui">{{item.sku}}</view>
				<view class="flexbetween" style="width: 100%;">
					<view class="hong_text main_size bold">￥{{item.pay_price}}</view>
					<view class="xiaohui">*{{item.goods_num}}</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top ffffff radius">
			<view class="main_size bold hei_text">备注</view>
			<textarea class="textareaclass hei_text main_size bold margin_top" style="height: 100rpx;"
				placeholder="请留言信息给商家" v-model="remarks"></textarea>
		</view>
		<!-- 固定底部 -->
		<view class="posibottom ffffff mainpadding">
			<view class="flexbetween">
				<view class="flexleft">
					<view class="main_size hei_text bold">合计：</view>
					<view class="hong_text bold titletext">¥{{dataAll.total_price}}</view>
				</view>
				<view class="submitbtn" style="width: 300rpx;" @click="pay">立即支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				goods_num: "",
				goods_id: "",
				goods_sku_unique: "",
				address_id: "",
				dataAll: {},
				remarks: "",
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.goods_num = data.goods_num
			this.goods_id = data.goods_id
			this.goods_sku_unique = data.goods_sku_unique
		},
		onShow() {
			uni.$off('addressId')
			uni.$on('addressId', data => {
				this.address_id = data
			})
			this.getdingdan()
		},
		methods: {
			getdingdan() {
				let data = {
					address_id: this.address_id,
					goods_num: this.goods_num,
					goods_id: this.goods_id,
					goods_sku_unique: this.goods_sku_unique,

				}
				httpRequest.request("/api/goods_order/order_show", 'POST', data, false, false, true).then(res => {
					if (res.code == 1) {
						this.dataAll = res.data
						if (res.data.address_info) {
							this.address_id = res.data.address_info.id
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			dizhi() {
				uni.navigateTo({
					url: '/pages_mine/shouhuodz?type=1'
				})
			},
			pay() {
				if (this.address_id == "") {
					httpRequest.toast("请选择地址")
					return
				}
				let data = {
					address_id: this.address_id,
					goods_num: this.goods_num,
					goods_id: this.goods_id,
					goods_sku_unique: this.goods_sku_unique,
					remarks: this.remarks,
					pay_price: this.dataAll.total_price,
				}
				uni.redirectTo({
					url: '/pages_mall/dingdanzf?msg=' + encodeURIComponent(JSON
						.stringify(data))
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.daqiantext {
		font-size: 36rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FD463E;
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.qianshu {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FD463E;
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #999999;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.biabox {
		height: 168rpx;
	}

	.dhtext {
		font-size: 30rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #228DFF;
	}

	.huisetext {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.yhxiank {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.gudingdb {
		padding: 30rpx 30rpx 60rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}

	.xiaohuangbtn {
		font-size: 32rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #FFFFFF;
		width: 226rpx;
		height: 76rpx;
		border-radius: 120rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #228DFF;
	}
</style>